package com.example.societiesSystem.controller;


import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.societiesSystem.common.R;
import com.example.societiesSystem.entity.Activities;
import com.example.societiesSystem.entity.SocietiesType;
import com.example.societiesSystem.entity.Teams;
import com.example.societiesSystem.service.ITeamsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 社团信息表 前端控制器
 * </p>
 *
 * @author 周欢
 * @since 2025-05-27
 */
@Api(tags = "社团信息表 前端控制器")
@CrossOrigin
@RestController
@RequestMapping("/teams")
public class TeamsController {

    @Resource
    private ITeamsService teamsService;

    @ApiOperation(value = "社团信息查询")
    @GetMapping("/page")
    public R pageAll(@RequestParam("pageIndex") Long pageIndex
            , @RequestParam("pageSize") Long pageSize
            , @RequestParam(value = "token" ,required = false) String token
            , @RequestParam(value = "name", required = false) String name
            , @RequestParam(value = "typeId", required = false) String typeId)
    {
        return R.data(teamsService.pageAll(pageIndex,pageSize,token,name,typeId));
    }


    @ApiOperation(value = "社团信息添加")
    @PostMapping("/add")
    public R add(@RequestBody Teams teams) {
        teams.setCreateTime(LocalDateTimeUtil.now());
        return R.data(teamsService.save(teams));
    }

    @ApiOperation(value = "根据userId查询社团活动信息")
    @GetMapping("/man")
    public R man(@RequestParam("manId") Long manId) {
        return R.data(teamsService.getBaseMapper().selectList(new LambdaQueryWrapper<Teams>().eq(Teams::getUserId,manId)));
    }

    @ApiOperation(value = "社团信息修改")
    @PostMapping("/upd")
    public R upd(@RequestBody Teams teams) {
        return R.data(teamsService.updateById(teams));
    }

    @ApiOperation(value = "社团信息删除")
    @PostMapping("/del")
    public R del(@RequestBody Teams teams) {
        return R.data(teamsService.removeById(teams));
    }
}
